<?php

namespace App\Controller;

use App\Interfaces\Controller\SkillControllerInterface;
use App\Library\System\Model\AppModel;
use App\Library\System\Model\SkillModel;
use App\Library\System\Sub\Auth;
use App\Library\System\Model\CategoryModel;

/**
 * Skill Controller
 *
 * @category   Controller
 * @package    App\Controller
 * @author     Tinh Nguyen <tinhntt@peslook.com>
 * @copyright  Peslook
 * @version    1.0
 * @since      Class available since Release 1.0
 */
class SkillController extends BaseController implements SkillControllerInterface
{
    /**
     * Skill
     *
     * @var SkillModel
     */
    public $skill;

    /**
     * Category
     *
     * @var CategoryModel
     */
    public $category;

    /**
     * Authentication
     *
     * @var Auth
     */
    public $auth;

    /**
     * App model instance
     *
     * @var AppModel
     */
    public $app;

    /**
     * Alias String
     *
     * @var Alias
     */
    public $alias;

    /**
     * Constructor
     *
     */
    public function __construct()
    {
        $this->auth = new Auth();
        $this->app = AppModel::getInstance();
    }

    /**
     * Index action
     *
     * @route /skill/category/{alias}
     * @return array|void ViewModel
     */
    public function indexAction()
    {
        echo 'SKILL CONTROLLER';
        die();

        //$this->alias = $this->route('alias');
        //$page = $this->loadCategory();
        //return $page;
    }

    /**
     * Load one Skill
     *
     * @return array|void ViewModel
     */

    private function item($page)
    {
        $this->skill = new SkillModel($this->alias);

        if (!$this->skill->isValid()) {
            return $this->error(404);
        }

        $less = array(
            'index_header',
            'skill_item_description',
            'skill_item_reference',
            'skill_item_reference_content',
            'skill_item_side_bar',
            'app_languages',
            'app_footer'
        );
        $coffee = array('language');
        $this->setLayout('skill/item', $less, $coffee);

        $page = $this->createPage('skill_description');
        //transfer some variable to page_view (skill and friend).
        $this->func($page);
        $page->login = $this->auth->login;

        $page_view = $this->getContentView($page);
        $page_view->skill = $this->skill;
        $page_view->login = $this->auth->login;
        $this->support($page);

        //$page_view->friend = $this->skill->getFriend();

        return $page;
    }

    /**
     * Load all Skills same Category
     *
     * @return array|void ViewModel
     */

    private function category($page)
    {
        $this->category = new CategoryModel($this->alias);

        if (!$this->category->getAllSkill()->toArray()) {
            return $this->loadSkill();
        }

        $less = array('index_header', 'skill_category', 'skill_category_tag', 'app_languages', 'app_footer');
        $coffee = array('language');
        $this->setLayout('skill/category', $less, $coffee);

        $page = $this->createPage('index');
        $this->func($page);
        $page->login = $this->auth->login;

        $page_view = $this->getContentView($page);
        $page_view->skills = $this->category->getAllSkill();
        $page_view->category_name = $this->category->getCategoryName();
        $page_view->login = $this->auth->login;

        $this->support($page);

        return $page;
    }

}
